package com.mars.foodserver.controller.app;

import com.mars.foodserver.controller.common.BaseController;
import com.mars.foodserver.response.FoodLikeResponse;
import com.mars.foodserver.response.result.R;
import com.mars.foodserver.service.IFoodLikeService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import lombok.AllArgsConstructor;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wq
 * @since 2021-07-21
 */
@RestController
@RequestMapping("/food")
@AllArgsConstructor
public class FoodLikeController extends BaseController {

    final IFoodLikeService foodLikeService;

    /**
     * 点赞
     *
     * @param foodId 美食ID
     * @param type   1 点赞 2 取消点赞
     */
    @GetMapping("/like")
    public R<Void> like(Integer foodId, Integer type) {
        foodLikeService.like(getUserId(), foodId, type);
        return R.success();
    }

    /**
     * 点赞列表
     *
     * @return R
     */
    @GetMapping("/foodLikes")
    public R<List<FoodLikeResponse>> foodLikes() {
        return R.success(foodLikeService.foodLikes(getUserId()));
    }
}
